<template xmlns="http://www.w3.org/1999/html">
  <div>
    <div style="margin-bottom: 5px">
      <el-input v-model="name" placeholder="请输入物品名" suffix-icon="el-icon-search" style="width: 200px;" @keyup.enter.native="loadPost"></el-input>
      <el-select style="margin-left: 5px;" v-model="storage" placeholder="请选择仓库">
        <el-option
            v-for="item in storageData"
            :key="item.id"
            :label="item.name"
            :value="item.id">
        </el-option>
      </el-select>
      <el-select style="margin-left: 5px;" v-model="goodstype" placeholder="请选择类别">
        <el-option
            v-for="item in goodsTypeData"
            :key="item.id"
            :label="item.name"
            :value="item.id">
        </el-option>
      </el-select>
      <el-button type="primary" style="margin-left: 5px;" @click="loadPost">查询</el-button>
      <el-button type="success" @click="resetParam">重置</el-button>
    </div>
    <el-table :data="tableData"
              :header-cell-style="{background:'#cccccc',color:'#555'}" border
    >
      <el-table-column prop="id" label="ID" width="60">
      </el-table-column>
      <el-table-column prop="goodsname" label="物品名" width="80">
      </el-table-column>
      <el-table-column prop="storagename" label="仓库" width="180" >
      </el-table-column>
      <el-table-column prop="goodstype" label="分类" width="80" >
      </el-table-column>
      <el-table-column prop="adminname" label="操作人" width="100" >
      </el-table-column>
      <el-table-column prop="username" label="申请人" width="80" >
      </el-table-column>
      <el-table-column prop="count" label="数量" width="80">
      </el-table-column>
      <el-table-column prop="outorin" label="出入库" width="80">
        <template slot-scope="scope">
          <el-tag
              effect="dark"
              plain
              :type="scope.row.outorin === '1' ? 'success' : 'danger'"
              disable-transitions>{{scope.row.outorin === '1' ? '入库' : '出库'}}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createtime" label="操作时间" width="180">
      </el-table-column>
      <el-table-column prop="remark" label="备注">
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>

export default {
  name: "RecodeManage",
  data() {
    return {
      user:JSON.parse(sessionStorage.getItem("CurUser")),
      storageData:[],
      tableData: [],
      goodsTypeData:[],
      pageSize:10,
      pageNum:1,
      total:0,
      storage: '',
      goodstype: '',
      username:'',
      name: '',
      centerDialogVisible:false,
      outorin:'',
      form:{
        id:'',
        name:'',
        storage:'',
        goodstype:'',
        count:'',
        remark:'',
      },
    };
  },
  methods:{
    handleSizeChange(val) {
      this.pageSize=val
      this.pageNum=1
      this.loadPost()
    },
    handleCurrentChange(val) {
      this.pageNum=val
      this.loadPost()
    },
    loadPost(){
      this.$axios.post(this.$httpUrl+'/record/listPageC1',{
        pageSize:this.pageSize,
        pageNum:this.pageNum,
        param:{
          name:this.name,
          storage: this.storage+'',
          goodstype: this.goodstype+'',
          roleId:this.user.roleId+'',
          userId:this.user.id+''
        }
      }).then(res=>res.data).then(res=>{
        if(res.code===200){
          this.tableData=res.data
          this.total=res.total
        }else {
          alert('获取数据失败')
        }
      })
    },
    loadStorage(){
      this.$axios.get(this.$httpUrl+'/storage/list').then(res=>res.data).then(res=>{
        if(res.code===200){
          this.storageData=res.data
        }else {
          alert('获取数据失败')
        }
      })
    },
    loadGoodsType(){
      this.$axios.get(this.$httpUrl+'/goodstype/list').then(res=>res.data).then(res=>{
        if(res.code===200){
          this.goodsTypeData=res.data
        }else {
          alert('获取数据失败')
        }
      })
    },
    resetParam(){
      this.name=''
      this.storage=''
      this.goodstype=''
    },
  },
  beforeMount() {
    this.loadGoodsType()
    this.loadStorage()
    this.loadPost()
  }
}
</script>

<style scoped>

</style>